<template>
  <div class="box">
    <div style="float: right;">


      <div style="display: flex ;">
        <el-select v-model="value" placeholder="请选择" size="mini" 
        style="  margin-top: 2vh; margin-right: 1vw;">
          <el-option
            v-for="item in selectData"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-input
        style="margin-top: 2vh;"
          v-model="input"
          suffix-icon="el-icon-search"
          placeholder="请输入"
          size="mini"
        ></el-input>
        <el-button size="mini" class="searchBtn" @click="search"
          >搜索</el-button
        >
      </div>
    </div>
    <div class="table-list">
      <el-table :data="data" border size="small" style="width: 100%">
        <el-table-column fixed prop="id" label="评论id"> </el-table-column>
        <el-table-column fixed prop="uid" label="发布者id"> </el-table-column>
        <el-table-column prop="vid" label="视频id"> </el-table-column>

        <el-table-column prop="content" width="300" label="内容"> </el-table-column>

        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button
              @click="ban(scope.row.id)"
              type="text"
              size="small"
              >封禁</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
      
      <script>
import { mapGetters } from "vuex";
export default {
  computed: {
    ...mapGetters(["baseUrl"]),
  },
  data() {
    return {
      dialoger: false,
      data: [],
      input: "",
      value:'content',
      selectData:[
        {value:'content',label:"按内容"},
        {
            value:'id',label:"按id"
        }
      ]
    };
  },
  methods: {

    async getData() {
      const { data: res } = await this.$http.get("/comments/s0" );
      if (res.code == 200) {
        this.data = res.data;
      }
    },
    async search() {
      const { data: res } = await this.$http.get("/comments/"+ this.value, {
        params: {
          value: this.input,
        },
      });
      {
        if (res.code == 200) {
          this.data = res.data;
        }
      }
    },
    async ban(cid){
        const { data: res } = await this.$http.get("/comments/ban/" + cid);
      if (res.code == 200) {
        this.$msg.fail("封禁成功");
      }
    }
  },
  created() {
    this.getData();
  },
};
</script>
      
      <style>
.box {
  width: 100%;
}
.table-list {
  height: 85vh; 
}
.searchBtn {
  border: 2px solid black;
  margin-left: 1vw;
  margin-top: 2vh;
}
</style>